using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VBBHIST
    {
        public DataRow Convert2BBHIST(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryBBHIST(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["BBHMANDANT"] = " ".PadRight(2 ); 
         dwReturn["BBHDATE"] = " ".PadRight(8 ); 
         dwReturn["BBHBAUMKRS"] = " ".PadRight(2 ); 
         dwReturn["BBHBAUMLFD"] = " ".PadRight(6 ); 
         dwReturn["BBHART"] = " ".PadRight(20 ); 
         dwReturn["BBHVAR"] = " ".PadRight(2 ); 
         dwReturn["BBHFARBE"] = " ".PadRight(10 ); 
         dwReturn["BBHZUSTAND"] = " ".PadRight(4 ); 
         dwReturn["BBHKETTTYP"] = " ".PadRight(6 ); 
         dwReturn["BBHKOLLINR"] = " ".PadRight(8 ); 
         dwReturn["BBHLO"] = " ".PadRight(2 ); 
         dwReturn["BBHLB"] = " ".PadRight(2 ); 
         dwReturn["BBHLP"] = " ".PadRight(8 ); 
         dwReturn["BBHFERTKZ"] = " ".PadRight(1 ); 
         dwReturn["BBHZS"] = " ".PadRight(1 ); 
         dwReturn["BBHSPSTA"] = " ".PadRight(2 ); 
         dwReturn["BBHSPGRD"] = " ".PadRight(2 ); 
         dwReturn["BBHTAX"] = " ".PadRight(3 ); 
         dwReturn["BBHLG"] = " ".PadRight(0 ); 
         dwReturn["BBHBSTKG"] = " ".PadRight(0 ); 
         dwReturn["BBHHHK1"] = " ".PadRight(0 ); 
         dwReturn["BBHHHK2"] = " ".PadRight(0 ); 
         dwReturn["BBHHHK3"] = " ".PadRight(0 ); 
         dwReturn["BBHHHK4"] = " ".PadRight(0 ); 
         dwReturn["BBHHHK5"] = " ".PadRight(0 ); 
         dwReturn["BBHHHK6"] = " ".PadRight(0 ); 
         dwReturn["BBHHHK7"] = " ".PadRight(0 ); 
         dwReturn["BBHHHK8"] = " ".PadRight(0 ); 
         dwReturn["BBHHHK9"] = " ".PadRight(0 ); 
         dwReturn["BBHHHK10"] = " ".PadRight(0 ); 
         dwReturn["BBHHHKG"] = " ".PadRight(0 ); 
         dwReturn["BBHAHK1"] = " ".PadRight(0 ); 
         dwReturn["BBHAHK2"] = " ".PadRight(0 ); 
         dwReturn["BBHAHK3"] = " ".PadRight(0 ); 
         dwReturn["BBHAHK4"] = " ".PadRight(0 ); 
         dwReturn["BBHAHK5"] = " ".PadRight(0 ); 
         dwReturn["BBHAHK6"] = " ".PadRight(0 ); 
         dwReturn["BBHAHK7"] = " ".PadRight(0 ); 
         dwReturn["BBHAHK8"] = " ".PadRight(0 ); 
         dwReturn["BBHAHK9"] = " ".PadRight(0 ); 
         dwReturn["BBHAHK10"] = " ".PadRight(0 ); 
         dwReturn["BBHAHKG"] = " ".PadRight(0 ); 
         dwReturn["BBHABPZAB"] = " ".PadRight(0 ); 
         dwReturn["BBHBPREIS"] = " ".PadRight(0 ); 
         dwReturn["BBHPART"] = " ".PadRight(5 ); 
         dwReturn["BBHAVPREIS"] = " ".PadRight(0 ); 
         dwReturn["BBHIPREIS"] = " ".PadRight(0 ); 
         dwReturn["BBHINDAT"] = " ".PadRight(0 ); 
         dwReturn["BBHFILLER"] = " ".PadRight(22 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapBBHIST(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveBBHIST(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryBBHIST(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapBBHIST(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertBBHIST(dwLocal, ITXDBVERSION);
            }
            UpdateBBHIST(dwLocal);
        }
        public void InsertBBHIST(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO BBHIST(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryBBHIST(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM BBHIST WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM BBHIST  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "BBHIST";
            Return = Result;
            return Return;
        }
        public void DeleteBBHIST(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM BBHIST   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateBBHIST(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE BBHIST SET "
                    +"BBHMANDANT= :BBHMANDANT,"
                    +"BBHDATE= :BBHDATE,"
                    +"BBHBAUMKRS= :BBHBAUMKRS,"
                    +"BBHBAUMLFD= :BBHBAUMLFD,"
                    +"BBHART= :BBHART,"
                    +"BBHVAR= :BBHVAR,"
                    +"BBHFARBE= :BBHFARBE,"
                    +"BBHZUSTAND= :BBHZUSTAND,"
                    +"BBHKETTTYP= :BBHKETTTYP,"
                    +"BBHKOLLINR= :BBHKOLLINR,"
                    +"BBHLO= :BBHLO,"
                    +"BBHLB= :BBHLB,"
                    +"BBHLP= :BBHLP,"
                    +"BBHFERTKZ= :BBHFERTKZ,"
                    +"BBHZS= :BBHZS,"
                    +"BBHSPSTA= :BBHSPSTA,"
                    +"BBHSPGRD= :BBHSPGRD,"
                    +"BBHTAX= :BBHTAX,"
                    +"BBHLG= :BBHLG,"
                    +"BBHBSTKG= :BBHBSTKG,"
                    +"BBHHHK1= :BBHHHK1,"
                    +"BBHHHK2= :BBHHHK2,"
                    +"BBHHHK3= :BBHHHK3,"
                    +"BBHHHK4= :BBHHHK4,"
                    +"BBHHHK5= :BBHHHK5,"
                    +"BBHHHK6= :BBHHHK6,"
                    +"BBHHHK7= :BBHHHK7,"
                    +"BBHHHK8= :BBHHHK8,"
                    +"BBHHHK9= :BBHHHK9,"
                    +"BBHHHK10= :BBHHHK10,"
                    +"BBHHHKG= :BBHHHKG,"
                    +"BBHAHK1= :BBHAHK1,"
                    +"BBHAHK2= :BBHAHK2,"
                    +"BBHAHK3= :BBHAHK3,"
                    +"BBHAHK4= :BBHAHK4,"
                    +"BBHAHK5= :BBHAHK5,"
                    +"BBHAHK6= :BBHAHK6,"
                    +"BBHAHK7= :BBHAHK7,"
                    +"BBHAHK8= :BBHAHK8,"
                    +"BBHAHK9= :BBHAHK9,"
                    +"BBHAHK10= :BBHAHK10,"
                    +"BBHAHKG= :BBHAHKG,"
                    +"BBHABPZAB= :BBHABPZAB,"
                    +"BBHBPREIS= :BBHBPREIS,"
                    +"BBHPART= :BBHPART,"
                    +"BBHAVPREIS= :BBHAVPREIS,"
                    +"BBHIPREIS= :BBHIPREIS,"
                    +"BBHINDAT= :BBHINDAT,"
                    +"BBHFILLER= :BBHFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("BBHMANDANT", OracleType.NVarChar).Value = dwData["BBHMANDANT"].ToString(); 
          or1.Parameters.Add("BBHDATE", OracleType.NVarChar).Value = dwData["BBHDATE"].ToString(); 
          or1.Parameters.Add("BBHBAUMKRS", OracleType.NVarChar).Value = dwData["BBHBAUMKRS"].ToString(); 
          or1.Parameters.Add("BBHBAUMLFD", OracleType.NVarChar).Value = dwData["BBHBAUMLFD"].ToString(); 
          or1.Parameters.Add("BBHART", OracleType.NVarChar).Value = dwData["BBHART"].ToString(); 
          or1.Parameters.Add("BBHVAR", OracleType.NVarChar).Value = dwData["BBHVAR"].ToString(); 
          or1.Parameters.Add("BBHFARBE", OracleType.NVarChar).Value = dwData["BBHFARBE"].ToString(); 
          or1.Parameters.Add("BBHZUSTAND", OracleType.NVarChar).Value = dwData["BBHZUSTAND"].ToString(); 
          or1.Parameters.Add("BBHKETTTYP", OracleType.NVarChar).Value = dwData["BBHKETTTYP"].ToString(); 
          or1.Parameters.Add("BBHKOLLINR", OracleType.NVarChar).Value = dwData["BBHKOLLINR"].ToString(); 
          or1.Parameters.Add("BBHLO", OracleType.NVarChar).Value = dwData["BBHLO"].ToString(); 
          or1.Parameters.Add("BBHLB", OracleType.NVarChar).Value = dwData["BBHLB"].ToString(); 
          or1.Parameters.Add("BBHLP", OracleType.NVarChar).Value = dwData["BBHLP"].ToString(); 
          or1.Parameters.Add("BBHFERTKZ", OracleType.NVarChar).Value = dwData["BBHFERTKZ"].ToString(); 
          or1.Parameters.Add("BBHZS", OracleType.NVarChar).Value = dwData["BBHZS"].ToString(); 
          or1.Parameters.Add("BBHSPSTA", OracleType.NVarChar).Value = dwData["BBHSPSTA"].ToString(); 
          or1.Parameters.Add("BBHSPGRD", OracleType.NVarChar).Value = dwData["BBHSPGRD"].ToString(); 
          or1.Parameters.Add("BBHTAX", OracleType.NVarChar).Value = dwData["BBHTAX"].ToString(); 
          or1.Parameters.Add("BBHLG", OracleType.NVarChar).Value = dwData["BBHLG"].ToString(); 
          or1.Parameters.Add("BBHBSTKG", OracleType.NVarChar).Value = dwData["BBHBSTKG"].ToString(); 
          or1.Parameters.Add("BBHHHK1", OracleType.NVarChar).Value = dwData["BBHHHK1"].ToString(); 
          or1.Parameters.Add("BBHHHK2", OracleType.NVarChar).Value = dwData["BBHHHK2"].ToString(); 
          or1.Parameters.Add("BBHHHK3", OracleType.NVarChar).Value = dwData["BBHHHK3"].ToString(); 
          or1.Parameters.Add("BBHHHK4", OracleType.NVarChar).Value = dwData["BBHHHK4"].ToString(); 
          or1.Parameters.Add("BBHHHK5", OracleType.NVarChar).Value = dwData["BBHHHK5"].ToString(); 
          or1.Parameters.Add("BBHHHK6", OracleType.NVarChar).Value = dwData["BBHHHK6"].ToString(); 
          or1.Parameters.Add("BBHHHK7", OracleType.NVarChar).Value = dwData["BBHHHK7"].ToString(); 
          or1.Parameters.Add("BBHHHK8", OracleType.NVarChar).Value = dwData["BBHHHK8"].ToString(); 
          or1.Parameters.Add("BBHHHK9", OracleType.NVarChar).Value = dwData["BBHHHK9"].ToString(); 
          or1.Parameters.Add("BBHHHK10", OracleType.NVarChar).Value = dwData["BBHHHK10"].ToString(); 
          or1.Parameters.Add("BBHHHKG", OracleType.NVarChar).Value = dwData["BBHHHKG"].ToString(); 
          or1.Parameters.Add("BBHAHK1", OracleType.NVarChar).Value = dwData["BBHAHK1"].ToString(); 
          or1.Parameters.Add("BBHAHK2", OracleType.NVarChar).Value = dwData["BBHAHK2"].ToString(); 
          or1.Parameters.Add("BBHAHK3", OracleType.NVarChar).Value = dwData["BBHAHK3"].ToString(); 
          or1.Parameters.Add("BBHAHK4", OracleType.NVarChar).Value = dwData["BBHAHK4"].ToString(); 
          or1.Parameters.Add("BBHAHK5", OracleType.NVarChar).Value = dwData["BBHAHK5"].ToString(); 
          or1.Parameters.Add("BBHAHK6", OracleType.NVarChar).Value = dwData["BBHAHK6"].ToString(); 
          or1.Parameters.Add("BBHAHK7", OracleType.NVarChar).Value = dwData["BBHAHK7"].ToString(); 
          or1.Parameters.Add("BBHAHK8", OracleType.NVarChar).Value = dwData["BBHAHK8"].ToString(); 
          or1.Parameters.Add("BBHAHK9", OracleType.NVarChar).Value = dwData["BBHAHK9"].ToString(); 
          or1.Parameters.Add("BBHAHK10", OracleType.NVarChar).Value = dwData["BBHAHK10"].ToString(); 
          or1.Parameters.Add("BBHAHKG", OracleType.NVarChar).Value = dwData["BBHAHKG"].ToString(); 
          or1.Parameters.Add("BBHABPZAB", OracleType.NVarChar).Value = dwData["BBHABPZAB"].ToString(); 
          or1.Parameters.Add("BBHBPREIS", OracleType.NVarChar).Value = dwData["BBHBPREIS"].ToString(); 
          or1.Parameters.Add("BBHPART", OracleType.NVarChar).Value = dwData["BBHPART"].ToString(); 
          or1.Parameters.Add("BBHAVPREIS", OracleType.NVarChar).Value = dwData["BBHAVPREIS"].ToString(); 
          or1.Parameters.Add("BBHIPREIS", OracleType.NVarChar).Value = dwData["BBHIPREIS"].ToString(); 
          or1.Parameters.Add("BBHINDAT", OracleType.NVarChar).Value = dwData["BBHINDAT"].ToString(); 
          or1.Parameters.Add("BBHFILLER", OracleType.NVarChar).Value = dwData["BBHFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
